package com.starblink.product.detail.dialog

import com.starblink.android.basic.adapter.BaseBindingVH
import com.starblink.android.basic.ext.visibleOrGone
import com.starblink.product.R
import com.starblink.product.databinding.ItemProductCheckoutBinding

class ProductSecureHolder(
    binding: ItemProductCheckoutBinding,
    val listener: () -> Unit
) :
    BaseBindingVH<String, ItemProductCheckoutBinding>(binding = binding) {

    override fun onBind(type: String, position: Int) {
        if (type == "More") {
            binding.tvMore.visibleOrGone(true) {}
            binding.iv.visibleOrGone(false) {}
        } else {
            binding.iv.setImageResource(showPayIcon(type))
        }

        binding.tvMore.setOnClickListener { listener.invoke() }
        binding.iv.setOnClickListener { listener.invoke() }
    }

    private fun showPayIcon(name: String?): Int {
        when (name) {
            "MASTERCARD" -> return R.mipmap.icon_product_pay_01
            "VISA" -> return R.mipmap.icon_product_pay_02
            "KLARNA" -> return R.mipmap.icon_product_pay_03
            "AMERICAN EXPRESS" -> return R.mipmap.icon_product_pay_04
            "PAYPAL" -> return R.mipmap.icon_product_pay_05
            "TRUSTLY" -> return R.mipmap.icon_product_pay_06
            "SWISH" -> return R.mipmap.icon_product_pay_07
            "QLIRO" -> return R.mipmap.icon_product_pay_08
            "DIBS" -> return R.mipmap.icon_product_pay_09
            "COLLECTOR" -> return R.mipmap.icon_product_pay_10
            "SVEA" -> return R.mipmap.icon_product_pay_11
            "APPLE PAY" -> return R.mipmap.icon_product_pay_12
            "DINERS CLUB" -> return R.mipmap.icon_product_pay_13
            "ECSTER" -> return R.mipmap.icon_product_pay_14
            "VIABILL" -> return R.mipmap.icon_product_pay_15
            "PAYSON" -> return R.mipmap.icon_product_pay_16
            "WALLEY" -> return R.mipmap.icon_product_pay_17
            "SANTANDER" -> return R.mipmap.icon_product_pay_18
        }
        return R.mipmap.icon_product_pay_01
    }
}